package com.wk1un2.web.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.wk1un2.service.ActivitySessService;
import com.wk1un2.service.ProductCategoryService;
import com.wk1un2.service.ProductPictService;
import com.wk1un2.service.ProductService;
import com.wk1un2.service.ProductSpecService;
import com.wk1un2.service.ArrposidProductService;
@Controller
public class ProductCategoryWebController {
	@Autowired
	ProductService productService;
	@Autowired
	ProductPictService ProductPictService;
	@Autowired
	ProductCategoryService ProductCategoryService;
	@Autowired
	ProductSpecService productSpecService;
	@Autowired
	ActivitySessService ActivitySessService;
	@Autowired
	ArrposidProductService ArrposidProductService;
	@RequestMapping("/Productdetails")
	public String Product(Model model,@RequestParam("p_id") String p_id) {
		Integer pid=null;
		if (p_id!=null||p_id!="") {
			pid=Integer.parseInt(p_id);
		}
		List<Map<String, Object>> pc = ProductCategoryService.getAll(0, 9999, null);
		List<Map<String, Object>> product = productService.getProduct(pid);
		List<Map<String, Object>> productspec = productSpecService.getAllindex(0,9999,pid);
		List<Map<String, Object>> productpict1 = ProductPictService.getPict(pid,1);
		List<Map<String, Object>> productpict2 = ProductPictService.getPict(pid,0);
		model.addAttribute("ProCate", new IndexWebController().getPc(pc));
		String pcat_name = null;
		List<Map<String, Object>> productCate = ProductCategoryService.getCategory(pcat_name);
		model.addAttribute("product", product);
		model.addAttribute("Cate", productCate);
		model.addAttribute("productspec",productspec);
		model.addAttribute("propict1", productpict1);
		model.addAttribute("propict2", productpict2);
		// 重定向到主页面的跳转方法
		return "Productdetails";
	}
	@RequestMapping("/ProductCategory")
	public String ProductCategory(Model model,@RequestParam("pcat_name") String pcat_name) {
		List<Map<String, Object>> pc = ProductCategoryService.getAll(0, 9999, null);
		List<Map<String, Object>> productCate = ProductCategoryService.getCategory(pcat_name);
		List<Map<String, Object>> rpro = ArrposidProductService.getRecPro("活动下方");
		model.addAttribute("ProCate", new IndexWebController().getPc(pc));
		model.addAttribute("Cate", productCate);
		model.addAttribute("pc", pc);
		model.addAttribute("rp", rpro);
		// 重定向到主页面的跳转方法
		return "ProductCategory";
	}
	
	
	
	
}
